﻿// See https://aka.ms/new-console-template for more information
using MdxParser;
using System.Text;
using System.Text.Json;

MdxDocument mdx = new MdxDocument(AppDomain.CurrentDomain.BaseDirectory + "data\\root.mdx", Encoding.GetEncoding("utf-16"));
Console.WriteLine(JsonSerializer.Serialize(mdx));

mdx.RecordDatas.ForEach(data =>
{
    if (data.IsBinary)
    {
        if (!Directory.Exists(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory + data.Key)))
            Directory.CreateDirectory(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory + data.Key));
        File.WriteAllBytes(AppDomain.CurrentDomain.BaseDirectory + data.Key, data.Data);
    }
    else
        Console.WriteLine("{0},{1}", data.Key, data.Text);
});
